<!DOCTYPE html>
<html class="um landscape min-width-240px min-width-320px min-width-480px min-width-768px min-width-1024px">
<head>
<title></title>
<meta charset="utf-8">
<meta name="viewport" content="target-densitydpi=device-dpi, width=device-width, initial-scale=1, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<link rel="stylesheet" href="skin/base.css" type="text/css"  />
<link rel="stylesheet" type="text/css" href="skin/user.css">
<link rel="stylesheet" href="skin/btn.css" type="text/css" />
<script src="js/zy_control.js"></script>
<script src="js/zy_click.js"></script>
<script src="js/login.js"></script>
<script src="js/config.js"></script>
<script src="js/common.js"></script>
</head>
<body ontouchstart>
<div id="main">
  <div class="user">
    <div class="user_my_head">
    	<div class="bg"></div>
    
      <div class="avatar" ontouchstart="zy_touch('down')"  onclick="picSeclet()" id="avatar"></div>
      <div class="nk" id='nk' onclick="oauth('user_info');"></div>
      <div class="praise yes"><span>0</span></div>
      <ul id="button">
      	<li onclick="oauth('login')">登录</li>
   	  </ul>
    </div>
   
    <ul class="user_my_menu">
      <li ontouchstart="zy_touch('down')" onclick="favorite()">收藏<span id='favorite'>0</span></li>
      <li ontouchstart="zy_touch('down')" onclick="fans()">粉丝<span id='fans'>0</span></li>
      <li ontouchstart="zy_touch('down')" onclick="followers()">关注<span id='followers'>0</span></li>
    </ul>
  </div>
</div>
</body>
<script>
    zy_init();
	var Users= new Users({});
	
	function picSeclet(){
		if(!Users.checkUser()){
			Login();return false;
		}
		uexImageBrowser.pick();
		uexImageBrowser.cbPick= function (opCode,dataType,data){
			if(dataType==0){
				var photos =data;
				if(photos==''){
					return false;
				}
				var url = OpenAPI.portrait_update+'/?client_id='+OpenAPI.client_id+'&access_token='+localStorage['access_token'];
				
				uexXmlHttpMgr.open(99,'post',url,"12000");
				uexXmlHttpMgr.setPostData(99,'1','portrait',photos);
				uexXmlHttpMgr.send(99);
				uexWindow.toast(1, 5, '头像修改中，请稍候~', 0);
			}
		}
	}
	
	
	function oauth(windowname){
		if(!Users.checkUser()){
			windowname='login';
			localStorage['login']="user";
		}
		uexWindow.open(windowname, '0', windowname+'.html', 2, '', '', 0x0);
	}
	
	
	function Login(){
		Users.logout();
		localStorage['login']='user';
		uexWindow.open('login', '0', 'login.html', 4, '', '', 0x0);
	}
	
	function oklogin(){
		if(Users.checkUser()){
			uexWindow.toast(1, 5, '加载中...', 0);
			$$('button').innerHTML='<li onclick="logout()">退出登录</li> <li onclick="oauth(\'user_info\')">详细资料</li>';	
			var url = OpenAPI.my_information+'/?client_id='+OpenAPI.client_id+'&access_token='+localStorage['access_token'];
	
			//logs(url);
			uexXmlHttpMgr.open(1,'post',url,"8000");
			uexXmlHttpMgr.send(1);
		
		}else{
			$$('button').innerHTML='<li onclick="oauth(\'login\')">用户登录</li>';
			$$('avatar').innerHTML = '';
			$$('nk').innerHTML = '';
		}
	}
	
	function logout(){
　　　　	uexWindow.cbConfirm=function(opId,dataType,data){
　　			if(data==0){
　　				Users.logout();
					oklogin();
					uexWindow.toast("0", "5", '退出成功~', 1000);
	　　　　　	}else{
					return;
				}
　　　　	}
　　　　	uexWindow.confirm("提示","是否退出登录?",["确定","取消"])
    }
	
	window.uexOnload = function(type){
		if (!type) {
			uexWindow.setBounce("1");
			uexWindow.showBounceView("0","#666","0");
			uexWindow.showBounceView("1","#666","0");
			uexXmlHttpMgr.onData = function(opId, status, data){
				uexXmlHttpMgr.close(opId);
				if (status == 1) {
					data = JSON.parse(data);
					uexWindow.closeToast();
					if(opId ==1){
						if(data['user']){
							$$('avatar').innerHTML = '<img src="' + data['portrait'] + '" />';
							$$('nk').innerHTML = data['name'];
							$$('favorite').innerHTML = data['favoriteCount'];
							$$('fans').innerHTML = data['fansCount'];
							$$('followers').innerHTML = data['followersCount'];
							
						}else{
							uexWindow.toast("0", "5", '请求个人资料失败', 1000);
						}
					}else if (opId == 99) {
							if(data['error'] == '200'){
								oklogin();
								uexWindow.toast("0", "5", '头像修改成功~', 1000);
							}else{
								uexWindow.toast("0", "5", '头像修改失败~', 1000);
							}
					}
				}else if(status ==-1){
					uexWindow.toast("0", "5", '请求超时', 1000);
				}
			}
			oklogin();
		}
	}
	
</script>
</html>